var AnimationBase = function () {
	
	var animationSpeed = 200;
    var starFieldAnimationSpeed = 8000;
    var shootingStarAnimationSpeed = 300;
    
    this.PlanetRotation = function (universeEntity, radius, currentPosition) {
        if (universeEntity == null || universeEntity.ParentEntity() == null || universeEntity.UniverseEntityType != UniverseEntityTypes.Planet)
            return;

        var parentcenter = universeEntity.ParentEntity().RelativeCenter();
        var entityCenter = universeEntity.RelativeCenter();
        var center = new Point(parentcenter.X - entityCenter.X, parentcenter.Y - entityCenter.Y);
        if (currentPosition == null)
            currentPosition = new Point(universeEntity.AssociatedJqObject.position().left, universeEntity.AssociatedJqObject.position().top);
        if (radius == null)
            radius = center.Distance(currentPosition);
        var nextPosition = BasicPhysics.RotationNextPosition(currentPosition, center, radius, universeEntity.AngularSpeed, universeEntity.SpinDirection);
        
        var animationUtility = this;
        universeEntity.AssociatedJqObject.animate({ left: nextPosition.X, top: nextPosition.Y }, animationSpeed, 'linear', function () {
            universeEntity.AssociatedJqObject.css("left", nextPosition.X + "px").css("top", nextPosition.Y + "px");
            animationUtility.PlanetRotation(universeEntity, radius, nextPosition);
        });
    };
    
    this.SolarSystemRotation = function (universeEntity, radius, currentPosition) {
        if (universeEntity == null || universeEntity.ParentEntity() == null || universeEntity.UniverseEntityType != UniverseEntityTypes.SolarSystem)
            return;

        var parentcenter = universeEntity.ParentEntity().RelativeCenter();
        var entityCenter = universeEntity.RelativeCenter();
        var center = new Point(parentcenter.X - entityCenter.X, parentcenter.Y - entityCenter.Y);
        if (currentPosition == null)
            currentPosition = new Point(universeEntity.AssociatedJqObject.position().left, universeEntity.AssociatedJqObject.position().top);
        if (radius == null)
            radius = center.Distance(currentPosition);
        var nextPosition = BasicPhysics.RotationNextPosition(currentPosition, center, radius, universeEntity.AngularSpeed, universeEntity.SpinDirection);
        
        var animationUtility = this;
        universeEntity.AssociatedJqObject.animate({ left: nextPosition.X, top: nextPosition.Y }, animationSpeed, 'linear', function () {
            universeEntity.AssociatedJqObject.css("left", nextPosition.X + "px").css("top", nextPosition.Y + "px");
            animationUtility.SolarSystemRotation(universeEntity, radius, nextPosition);
        });
    };
    
    this.StarFieldAnimation = function (starField, starFieldGeneratorFunc) {

        if (starField == null || starFieldGeneratorFunc == null)
            return null;

        var newStarFieldJq = starFieldGeneratorFunc(starField).css({ opacity: 0 });
        starField.AssociatedJqObject.parent().prepend(newStarFieldJq);

        newStarFieldJq.animate({ opacity: 0.5 }, starFieldAnimationSpeed, 'linear');

        var animationUtility = this;
        starField.AssociatedJqObject.animate({ opacity: 0 }, starFieldAnimationSpeed, 'linear', function () {
            starField.AssociatedJqObject.remove();
            starField.AssociatedJqObject = newStarFieldJq;
            animationUtility.StarFieldAnimation(starField, starFieldGeneratorFunc);
        });
    };
    
    this.ShootingStarAnimation = function (shootingStar, currentPosition, stop){
    	if (shootingStar == null)
            return null;
  
    	if (currentPosition == null)
            currentPosition = new Point(shootingStar.AssociatedJqObject.position().left, shootingStar.AssociatedJqObject.position().top);
    	
    	var nextPosition = BasicPhysics.VectorNextPosition(currentPosition, shootingStar.MovementVector);
    	var opacity = 1 - Number(shootingStar.AssociatedJqObject.css('opacity'));
    	var tailWidth = 100 - Number(shootingStar.AssociatedJqObject.children('.Tail').outerWidth());
    	
    	var animationUtility = this;
    	
    	//Anim types: 'swing', 'linear'
    	
    	shootingStar.AssociatedJqObject.animate({ left: nextPosition.X, top: nextPosition.Y, opacity: opacity }, shootingStarAnimationSpeed, 'linear', function(){
    		if(stop){
    			shootingStar.AssociatedJqObject.remove();
    			return;
    		}
    		animationUtility.ShootingStarAnimation(shootingStar, nextPosition, true);
    	});
    	
    	shootingStar.AssociatedJqObject.children('.Tail').animate({ width: tailWidth }, shootingStarAnimationSpeed, 'linear', function(){
    		if(stop)
    			return;
    		animationUtility.ShootingStarAnimation(shootingStar, nextPosition, true);
    	});
    	
    };
	
};